package com.yingside.collection.homework;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Test10 {

    public void init(){
        List<String> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            list.add(getStringRandom());
        }

        System.out.println("==========排序前==========");
        for (String s : list) {
            System.out.println("s = " + s);
        }

        System.out.println("==========排序后==========");
        Collections.sort(list);
        for (String s : list) {
            System.out.println("s = " + s);
        }
    }


    /**
     * 生成随机数
     * @param min 最小数
     * @param max 最大数
     * @return 生成最小和最大数之间的随机数
     */
    public int myRandom(int min, int max){
        int r = (int)(Math.random() * (max - min + 1) + min);
        return r;
    }

    public String getStringRandom(){
        String s = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int r = myRandom(1,10);
        StringBuffer sb = new StringBuffer();
        for (int j = 1; j <= r; j++) {
            char c = s.charAt(myRandom(0,s.length()-1));
            sb.append(c);
        }

        return sb.toString();
    }

    public static void main(String[] args) {
        Test10 test10 = new Test10();
        test10.init();
    }
}
